package com.ld.bisystem.wrapper.condition;

import cn.hutool.core.date.DateUtil;

import java.util.Date;

public enum DateTypeConstant{

    anon("无","","yyyy-MM-dd HH:mm:ss"),
    day("日","%Y-%m-%d","yyyy-MM-dd"),
    month("月","%Y-%m","yyyy-MM"),
    year("年","%Y","yyyy"),

    ;
    private final String labal;

    private final String formatType;

    private final String fomat;

    ;

    DateTypeConstant(String labal, String formatType, String fomat) {
        this.labal = labal;
        this.formatType="'"+formatType+"'";
        this.fomat=fomat;
    }

    public String getFormatType() {
        return formatType;
    }


    public String getFomat() {
        return fomat;
    }



    public String getLabel() {
        return labal;
    }


    public String getValue() {
        return this.name();
    }

    public String fomatDate(Date date){
        return DateUtil.format(date,this.fomat);
    }

    public Date parseDate(String str){
        return DateUtil.parse(str,this.fomat);
    }

    public Date offDate(String str){
        Date end = parseDate(str);
        return offDate(end);
    }


    public Date offDate(Date end){

        if(this == day){
            return DateUtil.offsetDay(end,1);
        }
        else if(this == month){
            return DateUtil.offsetMonth(end,1);
        }else if(this == year){
            return DateUtil.offsetMonth(end,12);
        }
        return null;
    }

}